05. Quiz: Volatility

Volatility literally refers to how "volatile" a stock is, meaning how unpredictably its price might change. A statistical measure of dispersion, such as standard deviation , is commonly used to measure volatility.

In the exercise below, you're given daily prices for two sample stocks. Compute the standard deviations of their log returns, and return the ticker symbol for the stock that is more volatile.

Start Quiz:

import pandas as pd
import numpy as np

def get_most_volatile(prices):
    """Return the ticker symbol for the most volatile stock.
    
    Parameters
    ----------
    prices : pandas.DataFrame
        a pandas.DataFrame object with columns: ['ticker', 'date', 'price']
    
    Returns
    -------
    ticker : string
        ticker symbol for the most volatile stock
    """
    # TODO: Fill in this function.
    pass


def test_run(filename='prices.csv'):
    """Test run get_most_volatile() with stock prices from a file."""
    prices = pd.read_csv(filename, parse_dates=['date'])
    print("Most volatile stock: {}".format(get_most_volatile(prices)))


if __name__ == '__main__':
    test_run()
price,date,ticker
104.0,2016-07-01,A
104.87815067615534,2016-07-05,A
104.41190933506331,2016-07-06,A
104.93195657145004,2016-07-07,A
104.42127356374375,2016-07-08,A
104.48233796748329,2016-07-11,A
103.40686762477397,2016-07-12,A
103.9591303830494,2016-07-13,A
104.28469233758739,2016-07-14,A
104.66676708484209,2016-07-15,A
104.17156610731607,2016-07-18,A
104.13991075455378,2016-07-19,A
104.79582404775178,2016-07-20,A
105.87675465461643,2016-07-21,A
105.93709383205703,2016-07-22,A
105.99824339629772,2016-07-25,A
106.66192069875746,2016-07-26,A
106.43128726583544,2016-07-27,A
107.24942817664525,2016-07-28,A
106.92252227151646,2016-07-29,A
107.19164012858971,2016-08-01,A
107.76739981019861,2016-08-02,A
106.79760036376025,2016-08-03,A
106.37017472757208,2016-08-04,A
107.25706082740422,2016-08-05,A
106.32520729915613,2016-08-08,A
106.39761885327727,2016-08-09,A
105.40582903661794,2016-08-10,A
104.76581330979386,2016-08-11,A
104.54658054564462,2016-08-12,A
104.16731852181039,2016-08-15,A
104.20780001476068,2016-08-16,A
104.7355761493416,2016-08-17,A
104.1535430975006,2016-08-18,A
104.19534374424578,2016-08-19,A
104.2475736064227,2016-08-22,A
104.86594308196418,2016-08-23,A
105.5339054469482,2016-08-24,A
104.89166888729558,2016-08-25,A
105.41404099234215,2016-08-26,A
105.84159342092589,2016-08-29,A
104.25883692067988,2016-08-30,A
104.34314558998801,2016-08-31,A
105.0531392172164,2016-09-01,A
104.7155555671814,2016-09-02,A
105.58843450059987,2016-09-06,A
105.82575994957008,2016-09-07,A
106.40576836769606,2016-09-08,A
106.33895474987045,2016-09-09,A
106.45935569714388,2016-09-12,A
104.97493607225907,2016-09-13,A
104.51324100589954,2016-09-14,A
104.56447114723393,2016-09-15,A
104.42426708739794,2016-09-16,A
104.36017878164039,2016-09-19,A
104.65702984256826,2016-09-20,A
103.8770651464119,2016-09-21,A
105.32574951231125,2016-09-22,A
106.230251704852,2016-09-23,A
106.49466606265055,2016-09-26,A
107.28862190975128,2016-09-27,A
106.90267998732097,2016-09-28,A
106.56629592520223,2016-09-29,A
105.08773418645492,2016-09-30,A
104.7124724776131,2016-10-03,A
104.11672058372292,2016-10-04,A
103.84410015144081,2016-10-05,A
102.9642307762594,2016-10-06,A
104.16179785387305,2016-10-07,A
104.93050731747206,2016-10-10,A
105.97005797025622,2016-10-11,A
104.98281570660502,2016-10-12,A
105.81152696173264,2016-10-13,A
106.22262800781161,2016-10-14,A
106.27313381187071,2016-10-17,A
106.45384136146963,2016-10-18,A
107.72994596430657,2016-10-19,A
108.01352782071622,2016-10-20,A
108.65409495699907,2016-10-21,A
108.77072832379997,2016-10-24,A
109.50407838955655,2016-10-25,A
109.94799240486039,2016-10-26,A
110.1384286324776,2016-10-27,A
110.41164125212488,2016-10-28,A
110.99180153896083,2016-10-31,A
111.68924790246957,2016-11-01,A
112.15238938011582,2016-11-02,A
111.34045301062294,2016-11-03,A
111.60930907791592,2016-11-04,A
110.44129521062405,2016-11-07,A
110.03869380880164,2016-11-08,A
109.91185342518776,2016-11-09,A
110.8208301301043,2016-11-10,A
109.80198898321221,2016-11-11,A
109.61174221075348,2016-11-14,A
109.19186431107813,2016-11-15,A
108.94667888415138,2016-11-16,A
109.20028536548483,2016-11-17,A
109.15540847031824,2016-11-18,A
108.62400996724136,2016-11-21,A
108.99543759775818,2016-11-22,A
107.74700405713533,2016-11-23,A
107.97494327657327,2016-11-25,A
107.59052185552868,2016-11-28,A
106.39331171827483,2016-11-29,A
107.00318574657564,2016-11-30,A
107.3673403807312,2016-12-01,A
106.4260979750733,2016-12-02,A
106.32989842738297,2016-12-05,A
105.7805053952623,2016-12-06,A
105.06604606111044,2016-12-07,A
105.98344324091393,2016-12-08,A
105.83297898254067,2016-12-09,A
104.57978697805429,2016-12-12,A
103.97471014292363,2016-12-13,A
104.54551837965572,2016-12-14,A
104.32558680495227,2016-12-15,A
104.61834849436612,2016-12-16,A
104.86093524328373,2016-12-19,A
105.0870744880627,2016-12-20,A
104.91445082632119,2016-12-21,A
105.63621189411353,2016-12-22,A
105.97928946012455,2016-12-23,A
105.58959421203889,2016-12-27,A
106.2533164278796,2016-12-28,A
105.98952520981197,2016-12-29,A
104.84789839231375,2016-12-30,A
105.24633220461182,2017-01-03,A
105.49340322050347,2017-01-04,A
106.2019977529751,2017-01-05,A
105.44350526507864,2017-01-06,A
105.49373493263305,2017-01-09,A
104.57496795441946,2017-01-10,A
105.08185066165795,2017-01-11,A
105.8043287751058,2017-01-12,A
106.34746250326555,2017-01-13,A
106.55864244876634,2017-01-17,A
105.54359222176907,2017-01-18,A
105.31256328011446,2017-01-19,A
105.39279084065949,2017-01-20,A
105.67218523065509,2017-01-23,A
105.56024479446687,2017-01-24,A
105.44985276071807,2017-01-25,A
106.31128572467486,2017-01-26,A
106.0524503090274,2017-01-27,A
106.88116153915816,2017-01-30,A
105.93310285842674,2017-01-31,A
106.054179476072,2017-02-01,A
106.22707555487085,2017-02-02,A
106.8007069718136,2017-02-03,A
107.37603401487004,2017-02-06,A
106.52791913834007,2017-02-07,A
105.01778888188377,2017-02-08,A
105.57984370981511,2017-02-09,A
105.30917881279444,2017-02-10,A
106.46775267747175,2017-02-13,A
105.97991225598228,2017-02-14,A
104.60316567758687,2017-02-15,A
105.9442486926104,2017-02-16,A
106.91494144521057,2017-02-17,A
107.43307249661517,2017-02-21,A
106.70206379404051,2017-02-22,A
107.40228313476484,2017-02-23,A
107.53839792123946,2017-02-24,A
106.76464530625195,2017-02-27,A
106.93925373830918,2017-02-28,A
107.5418906430049,2017-03-01,A
107.50102674603055,2017-03-02,A
107.11904057612496,2017-03-03,A
107.90849017717056,2017-03-06,A
107.55955829065194,2017-03-07,A
107.00984336955489,2017-03-08,A
107.28954139024019,2017-03-09,A
107.07318273895147,2017-03-10,A
108.54767657360567,2017-03-13,A
109.02407701236174,2017-03-14,A
110.42438916911125,2017-03-15,A
109.82712229883415,2017-03-16,A
109.41778128903894,2017-03-17,A
109.26268620383128,2017-03-20,A
109.15865916961283,2017-03-21,A
109.59201397402276,2017-03-22,A
109.1792051523596,2017-03-23,A
109.83347382989604,2017-03-24,A
108.99212612197309,2017-03-27,A
108.87667229736903,2017-03-28,A
109.11567867513011,2017-03-29,A
110.14970695659157,2017-03-30,A
110.193384360099,2017-03-31,A
110.14327400337842,2017-04-03,A
109.68425503645079,2017-04-04,A
109.79211154929487,2017-04-05,A
108.89701873854071,2017-04-06,A
109.08632179090107,2017-04-07,A
108.17607176592361,2017-04-10,A
106.97790913533136,2017-04-11,A
106.64905188276357,2017-04-12,A
106.11364798173491,2017-04-13,A
106.55383329339755,2017-04-17,A
106.9106877870171,2017-04-18,A
105.71149390238746,2017-04-19,A
106.29742705474031,2017-04-20,A
105.03899798634544,2017-04-21,A
105.96703426972067,2017-04-24,A
107.36712012874791,2017-04-25,A
108.6208194926428,2017-04-26,A
108.9632436272641,2017-04-27,A
107.57288320385558,2017-04-28,A
108.03127019947732,2017-05-01,A
108.35427662464336,2017-05-02,A
109.18194160695627,2017-05-03,A
109.71029080642788,2017-05-04,A
109.68981407560253,2017-05-05,A
110.98990496310962,2017-05-08,A
111.36177549687392,2017-05-09,A
111.0122081014912,2017-05-10,A
111.01190922810297,2017-05-11,A
110.01130626168074,2017-05-12,A
110.17162372275988,2017-05-15,A
110.17803187059303,2017-05-16,A
110.19570682399144,2017-05-17,A
110.29063439657831,2017-05-18,A
111.24479607852692,2017-05-19,A
111.24161280899963,2017-05-22,A
110.01013582093175,2017-05-23,A
110.76888911924776,2017-05-24,A
111.6966162532818,2017-05-25,A
111.74628297709928,2017-05-26,A
113.25353439563817,2017-05-30,A
113.64918192700323,2017-05-31,A
115.62868405133601,2017-06-01,A
116.01725792321129,2017-06-02,A
116.95293107003178,2017-06-05,A
116.67816960489264,2017-06-06,A
115.075779256282,2017-06-07,A
116.9717350978082,2017-06-08,A
117.10670353137289,2017-06-09,A
117.82214878154537,2017-06-12,A
117.72421590630458,2017-06-13,A
118.08592369502983,2017-06-14,A
118.93240834542965,2017-06-15,A
120.38779792070359,2017-06-16,A
120.35281297437548,2017-06-19,A
120.49000836617397,2017-06-20,A
120.47502037526715,2017-06-21,A
120.25913142194942,2017-06-22,A
119.84080802849351,2017-06-23,A
120.08306159685034,2017-06-26,A
120.28304898318079,2017-06-27,A
120.91696662057332,2017-06-28,A
120.3165751209433,2017-06-29,A
120.41291993373277,2017-06-30,A
82.0,2016-07-01,B
82.39027880655584,2016-07-05,B
82.5652803416583,2016-07-06,B
83.28982590247573,2016-07-07,B
83.05130145004524,2016-07-08,B
83.03690171325026,2016-07-11,B
82.80883463604872,2016-07-12,B
81.9640349848397,2016-07-13,B
81.63938890786395,2016-07-14,B
81.33741770742532,2016-07-15,B
81.48823320866978,2016-07-18,B
82.10314711803804,2016-07-19,B
82.8846725271368,2016-07-20,B
82.63293088681507,2016-07-21,B
81.9617000080722,2016-07-22,B
81.3248953346761,2016-07-25,B
80.70318943513297,2016-07-26,B
80.7394111404197,2016-07-27,B
81.83180550111113,2016-07-28,B
80.95658815803478,2016-07-29,B
81.46514391615686,2016-08-01,B
81.13109903282427,2016-08-02,B
80.26017085643664,2016-08-03,B
80.35970150328237,2016-08-04,B
81.48344911553264,2016-08-05,B
82.06592814189158,2016-08-08,B
82.56118876268187,2016-08-09,B
82.26380284063097,2016-08-10,B
82.30163747725068,2016-08-11,B
83.93789798278286,2016-08-12,B
83.04507167400811,2016-08-15,B
83.80853376158022,2016-08-16,B
83.07677278681959,2016-08-17,B
83.6899265829473,2016-08-18,B
83.11858277067248,2016-08-19,B
83.88177540392275,2016-08-22,B
84.38855925172832,2016-08-23,B
84.4517053492405,2016-08-24,B
85.32826368391717,2016-08-25,B
85.25572455037593,2016-08-26,B
85.45369582981279,2016-08-29,B
82.89276617370653,2016-08-30,B
82.39310348285989,2016-08-31,B
82.09160159936978,2016-09-01,B
83.48634495003132,2016-09-02,B
83.39078350241046,2016-09-06,B
84.06191212588838,2016-09-07,B
85.02622285922729,2016-09-08,B
85.79473262046142,2016-09-09,B
85.95485776638273,2016-09-12,B
86.03017534219492,2016-09-13,B
86.18833955665835,2016-09-14,B
85.52461691096536,2016-09-15,B
85.32941725680423,2016-09-16,B
84.4754761789464,2016-09-19,B
84.70293734139364,2016-09-20,B
86.02555064275799,2016-09-21,B
86.42752100632038,2016-09-22,B
85.94386093393683,2016-09-23,B
85.40241852698998,2016-09-26,B
86.22175546963237,2016-09-27,B
85.21201731302669,2016-09-28,B
86.31887184621411,2016-09-29,B
85.59827573296502,2016-09-30,B
86.2984510276552,2016-10-03,B
85.08233689183996,2016-10-04,B
84.40225404818582,2016-10-05,B
83.89818943813344,2016-10-06,B
83.97041903721697,2016-10-07,B
85.32622922119015,2016-10-10,B
85.12565083476036,2016-10-11,B
85.12281542235286,2016-10-12,B
86.6259168504227,2016-10-13,B
85.80228123552082,2016-10-14,B
85.04070505031703,2016-10-17,B
85.36766756055604,2016-10-18,B
87.6204554310589,2016-10-19,B
89.02251393215508,2016-10-20,B
88.32782026095106,2016-10-21,B
89.22758484865925,2016-10-24,B
88.43672926219107,2016-10-25,B
89.45480054147143,2016-10-26,B
87.68355592039403,2016-10-27,B
88.64308822074702,2016-10-28,B
89.61785546585126,2016-10-31,B
90.55335571917013,2016-11-01,B
90.99335609151478,2016-11-02,B
92.22557006367231,2016-11-03,B
91.87016448900445,2016-11-04,B
91.16324495260513,2016-11-07,B
91.97947684341321,2016-11-08,B
92.9388398259952,2016-11-09,B
93.83216203753813,2016-11-10,B
93.47450786773602,2016-11-11,B
93.52749505841169,2016-11-14,B
92.25139300655276,2016-11-15,B
92.6579295965024,2016-11-16,B
90.8460864461842,2016-11-17,B
92.26968099527326,2016-11-18,B
91.70734981186841,2016-11-21,B
93.91656122726128,2016-11-22,B
92.13048804882813,2016-11-23,B
94.50438654640928,2016-11-25,B
94.7473149332066,2016-11-28,B
93.60471986249573,2016-11-29,B
96.27322616539266,2016-11-30,B
96.49529801580991,2016-12-01,B
97.02338261821984,2016-12-02,B
96.50506703372528,2016-12-05,B
98.8932336108936,2016-12-06,B
97.89711389102638,2016-12-07,B
97.99051791211899,2016-12-08,B
97.32260000897432,2016-12-09,B
97.23362350718472,2016-12-12,B
98.16060227515855,2016-12-13,B
98.09988356446931,2016-12-14,B
99.43077149203111,2016-12-15,B
99.85154881581289,2016-12-16,B
99.77168199407996,2016-12-19,B
98.57347327563868,2016-12-20,B
98.87673382540558,2016-12-21,B
96.86460249679232,2016-12-22,B
97.55459168973407,2016-12-23,B
96.75444212751852,2016-12-27,B
96.53636247536876,2016-12-28,B
96.66687806079284,2016-12-29,B
97.09818655273773,2016-12-30,B
97.4246794626995,2017-01-03,B
96.25321335171205,2017-01-04,B
98.07707212588463,2017-01-05,B
97.47637619492231,2017-01-06,B
97.17261330376051,2017-01-09,B
98.18287590193282,2017-01-10,B
96.60731464543798,2017-01-11,B
96.18490557060629,2017-01-12,B
98.12929159587712,2017-01-13,B
99.04024505384292,2017-01-17,B
100.40711408022766,2017-01-18,B
97.6142634549575,2017-01-19,B
96.91469086777869,2017-01-20,B
96.03308160246988,2017-01-23,B
94.67758089626902,2017-01-24,B
93.14393329306974,2017-01-25,B
93.35420474896627,2017-01-26,B
94.29333544746564,2017-01-27,B
95.22833211549626,2017-01-30,B
94.92344677569346,2017-01-31,B
95.59245920214356,2017-02-01,B
95.62790240963264,2017-02-02,B
94.0018889402374,2017-02-03,B
92.47296426289,2017-02-06,B
91.51783770990026,2017-02-07,B
91.40255608848152,2017-02-08,B
93.25854765424515,2017-02-09,B
93.18331166208614,2017-02-10,B
92.13037753774564,2017-02-13,B
91.84356701430782,2017-02-14,B
92.79502254361455,2017-02-15,B
92.6785069248823,2017-02-16,B
91.8735732122646,2017-02-17,B
91.44690931230701,2017-02-21,B
92.26204094774529,2017-02-22,B
90.81548030617226,2017-02-23,B
89.80658306431484,2017-02-24,B
90.17597659469678,2017-02-27,B
90.10693334426504,2017-02-28,B
89.44123556809093,2017-03-01,B
90.92017727921954,2017-03-02,B
91.24226722173694,2017-03-03,B
91.10636066606065,2017-03-06,B
90.90706267487296,2017-03-07,B
89.36541587627681,2017-03-08,B
89.16817853896772,2017-03-09,B
89.28109777301604,2017-03-10,B
88.18385663504705,2017-03-13,B
89.63284881040232,2017-03-14,B
88.95617195420631,2017-03-15,B
89.96502203996023,2017-03-16,B
88.59562207274043,2017-03-17,B
88.82540278976087,2017-03-20,B
89.24678330072808,2017-03-21,B
88.78047795214775,2017-03-22,B
88.9487272120044,2017-03-23,B
89.41478854695114,2017-03-24,B
88.92248149816561,2017-03-27,B
87.988788488148,2017-03-28,B
87.11638341153639,2017-03-29,B
86.1198554718709,2017-03-30,B
86.242127233922,2017-03-31,B
86.43147343476782,2017-04-03,B
89.07269450186917,2017-04-04,B
88.17254919729515,2017-04-05,B
88.46359793269824,2017-04-06,B
88.30925697543307,2017-04-07,B
88.65761522857981,2017-04-10,B
90.5081199838781,2017-04-11,B
92.4979509692623,2017-04-12,B
90.68911515608092,2017-04-13,B
89.71974497585497,2017-04-17,B
89.12558905248157,2017-04-18,B
90.8676249539463,2017-04-19,B
91.09032198614868,2017-04-20,B
90.82320328206988,2017-04-21,B
91.0722931006302,2017-04-24,B
92.69459816226578,2017-04-25,B
91.35337139111843,2017-04-26,B
92.18726462872965,2017-04-27,B
91.21147804499351,2017-04-28,B
91.79642103161204,2017-05-01,B
92.73325664817861,2017-05-02,B
94.02812162396309,2017-05-03,B
94.96062057331646,2017-05-04,B
95.03945744418283,2017-05-05,B
94.44790715081704,2017-05-08,B
92.04511385264384,2017-05-09,B
90.68985148876533,2017-05-10,B
90.01302130697961,2017-05-11,B
90.10756969547089,2017-05-12,B
88.54779614197132,2017-05-15,B
88.35010517052422,2017-05-16,B
90.74087293165948,2017-05-17,B
91.49142536675627,2017-05-18,B
92.66721888788159,2017-05-19,B
94.07897719543152,2017-05-22,B
93.82942095694445,2017-05-23,B
91.06857281399579,2017-05-24,B
92.62917864757621,2017-05-25,B
91.9298298269509,2017-05-26,B
92.22086001780352,2017-05-30,B
93.16304289633705,2017-05-31,B
94.85710014228668,2017-06-01,B
92.99913773397444,2017-06-02,B
90.53482833177634,2017-06-05,B
90.93567181705905,2017-06-06,B
90.99269787228859,2017-06-07,B
91.93666221991097,2017-06-08,B
91.37121707577406,2017-06-09,B
91.25853315210013,2017-06-12,B
91.06518272817927,2017-06-13,B
89.739451456876,2017-06-14,B
90.05827140475263,2017-06-15,B
89.6027597465541,2017-06-16,B
89.26635772866344,2017-06-19,B
87.92067133714045,2017-06-20,B
86.4712243241644,2017-06-21,B
86.96530035968235,2017-06-22,B
85.98096349798118,2017-06-23,B
85.29307815608935,2017-06-26,B
86.52142468257212,2017-06-27,B
85.5969736206676,2017-06-28,B
86.38499946064206,2017-06-29,B
87.47975707277152,2017-06-30,B